function [point,shift,wrapping_size] = get_Curvelet_point_shift(radial,curvelet_dir,curvelet_supp_width,origin,n,m,num_radial)
% Computes 
% - smallest axial aligned rectangle represented by the upper left
%   and lower right point=[uly, lry ;ulx, lrx]
% - size of the wrapping window
% - shift of the wrapping windows
%
%author: Sebastian Schmelcher; version: 2012-09-03


half_supp_width=curvelet_supp_width/2;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% compute axial aligned rectangle containg complete curvelet %%%   
r1=floor(2^(radial+1)/3);%*cos(curvelet_supp_width));
r2=ceil(5*2^(radial)/3);

 cp=cos(curvelet_dir+half_supp_width);
 cm=cos(curvelet_dir-half_supp_width);
 sp=sin(curvelet_dir+half_supp_width);
 sm=sin(curvelet_dir-half_supp_width);

% %%% Boundarie points
% tl=r2*[sp,cp]; %[y,x]
% tr=r2*[sm,cm];
% bl=r1*[sp,cp];
% br=r1*[sm,cm];
    
if(abs(curvelet_dir) < 3/4*pi&& abs(curvelet_dir) >pi/4)
    %North or South
    x=r2*[cp,cm];        
    x=[x,r1*[cp,cm]];      
    y=[r1*[sp,sm],r2*[sp,sm]];
    if( abs(curvelet_dir-pi/2)<curvelet_supp_width || abs(curvelet_dir-pi/2)>pi-curvelet_supp_width)
        %curvelet intersects vertical axis
        if(curvelet_dir<0)
            y(end+1)=-r2;
        else
            y(end+1)=r2; 
        end
    end
else
    %East or West  
    x=r2*[cp,cm];        
    x=[x,r1*[cp,cm]];    
    y=[r1*[sp,sm],r2*[sp,sm]];
    if( abs(curvelet_dir)<curvelet_supp_width || abs(curvelet_dir)>pi-curvelet_supp_width)
        %curvelet intersects horizontal axis
        if( abs(curvelet_dir)<pi/2)
            x(end+1)=r2;
        else
            x(end+1)=-r2;
        end
    end
end
% curvelet_dir
% pi-curvelet_supp_width
% curvelet_supp_width
% x
% y
point_ul=[max(1,origin(1)+floor(min(y))),max(1,origin(2)+floor(min(x)))];
point_lr=[min(n,origin(1)+ceil(max(y))),min(m,origin(2)+ceil(max(x)))];
point=[point_ul;point_lr];


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% length and width of mother curvelet %%%
l=ceil(5*2^(radial)/3-2^(radial+1)/3*cos(half_supp_width));
%l=ceil(5*2^(radial)/3)-floor(2^(radial+1)/3*cos(half_supp_width));
b=2*ceil(abs(5/3*2^(radial)*sin(half_supp_width)));



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% compute size of wrapping rectangle %%%
%%% compute shift in y direction of wrapping window %%%

%curvelet_dir
xshift=0;
yshift=0;
if(abs(curvelet_dir) < 3/4*pi && abs(curvelet_dir) >pi/4)
    %North or South
    wrapping_size=[ceil(abs(l*sin(curvelet_dir))),ceil(abs(b/sin(curvelet_dir)))];
    if(curvelet_dir >0)
        %North
        xshift=ceil(cos(curvelet_dir)*l);
    else
        %South
        xshift=-floor(cos(curvelet_dir)*l);  
    end

else
    %East or West    
    wrapping_size=[ceil(abs(b/cos(curvelet_dir))),ceil(abs(l*cos(curvelet_dir)))];
    if(abs(curvelet_dir)<pi/2)
        %East
        yshift=ceil(sin(curvelet_dir)*l);
    else
        %West
        yshift=-floor(sin(curvelet_dir)*l);
    end
end


shift=[yshift,xshift];


if(prod(wrapping_size)>prod([point(2)-point(1),point(4)-point(3)]))
    %shouldn't happen, but may happen due to the use of ceil 
    %fprintf('no wrapping here!');
    wrapping_size=[point(2)-point(1),point(4)-point(3)];
    shift=[0,0];    
end